﻿@model IPagedList


@if (Model.TotalCount > 0)
{
    var controller = this.ViewContext.RouteData.Values["controller"].ToString();
    var action = this.ViewContext.RouteData.Values["action"].ToString();
    //if (Model.PageCount < 2 && Model.PagingDisplayMode == PagingDisplayMode.IfNeeded)
    //{
    //}
    //elseModel.Model.GroupSize
    //{
    int offset = (Model.GroupSize) / 2, temp = 0;
    int pageStart = Model.PageIndex - offset, pageEnd = Model.PageIndex + offset, curPage = 0;
    <div style="text-align: center">
        <nav>
            <ul class="pager">
                @if (Model.HasPreviousPage)
                {
                    <li>
                        <a href='@PageHelper.GetPagerUrl(this.ViewContext,Model.PageIndex - 1)' aria-label="Previous">
                            <span aria-hidden="true">&laquo;</span>
                        </a>
                    </li>
                }
                else
                {
                    <li class="disabled">
                        <a href="javascript:void(0)" aria-label="Previous">
                            <span aria-hidden="true">&laquo;</span>
                        </a>
                    </li>
                }
                @if (pageStart <= 1 && pageEnd >= Model.PageCount)
                {
                    for (var i = 0; i <= Model.GroupSize; i++)
                    {
                        curPage = pageStart + i;
                        if ((curPage >= 1) && (curPage <= Model.PageCount))
                        {
                            if (curPage == Model.PageIndex)
                            {
                                <li class="current">
                                    <a href="javascript:void(0)">
                                        @Model.PageIndex<span class="sr-only"></span>
                                    </a>
                                </li>
                            }
                            else
                            {
                                <li>
                                    <a href='@PageHelper.GetPagerUrl(this.ViewContext,curPage)'>
                                        @curPage <span class="sr-only"> @curPage </span>
                                    </a>
                                </li>
                            }
                        }
                    }
                }
                else
                {
                    if (pageStart > 1)
                    {
                        <li>
                            <a href='@PageHelper.GetPagerUrl(this.ViewContext,1)'>1<span class="sr-only">1</span></a>
                        </li>
                        <li>
                            <a href='@PageHelper.GetPagerUrl(this.ViewContext,2)'>2<span class="sr-only">1</span></a>
                        </li>
                        <li class="disbaled">
                            <a href="javascript:void(0)">...<span class="sr-only">...</span></a>
                        </li>
                        temp = Model.PageIndex - offset / 2;
                        curPage = temp;
                        for (var i = 0; i <= offset / 2 + 1; i++)
                        {
                            curPage = temp + i;
                            if ((curPage >= 1) && (curPage <= Model.PageCount))
                            {
                                if (curPage == Model.PageIndex)
                                {
                                    <li class="active">
                                        <a href="javascript:void(0)">
                                            @Model.PageIndex<span class="sr-only"></span>
                                        </a>
                                    </li>
                                    break;
                                }
                                else
                                {
                                    <li>
                                        <a href='@PageHelper.GetPagerUrl(this.ViewContext, curPage)'>
                                            @curPage <span class="sr-only"> @curPage </span>
                                        </a>
                                    </li>
                                }
                            }
                        }
                    }
                    else
                    {
                        for (var i = 0; i <= offset; i++)
                        {
                            curPage = pageStart + i;
                            if ((curPage >= 1) && (curPage <= Model.PageCount))
                            {
                                if (curPage == Model.PageIndex)
                                {
                                    <li class="active">
                                        <a href="javascript:void(0)">
                                            @Model.PageIndex<span class="sr-only"></span>
                                        </a>
                                    </li>
                                    break;
                                }
                                else
                                {
                                    <li>
                                        <a href='@PageHelper.GetPagerUrl(this.ViewContext,curPage)'>
                                            @curPage <span class="sr-only"> @curPage </span>
                                        </a>
                                    </li>
                                }
                            }
                        }
                    }
                    if (pageEnd < Model.PageCount)
                    {
                        temp = Model.PageIndex + 1;
                        curPage = temp;
                        for (var i = 0; i <= offset / 2 && curPage <= Model.PageCount; i++)
                        {
                            curPage = temp + i;
                            if ((curPage >= 1) && (curPage <= Model.PageCount))
                            {
                                <li>
                                    <a href='@PageHelper.GetPagerUrl(this.ViewContext, curPage)'>
                                        @curPage <span class="sr-only"> @curPage </span>
                                    </a>
                                </li>
                            }
                        }
                        <li class="disbaled">
                            <a href="javascript:void(0)">...<span class="sr-only">...</span></a>
                        </li>
                        <li>
                            <a href='@PageHelper.GetPagerUrl(this.ViewContext,Model.PageCount - 1)'>
                                @(Model.PageCount - 1)<span class="sr-only">@(Model.PageCount - 1)</span>
                            </a>
                        </li>
                        <li>
                            <a href='@PageHelper.GetPagerUrl(this.ViewContext,Model.PageCount)'>
                                @Model.PageCount<span class="sr-only">@Model.PageCount</span>
                            </a>
                        </li>
                    }
                    else
                    {
                        curPage = Model.PageIndex;
                        for (var i = 0; i <= offset && curPage <= Model.PageCount; i++)
                        {
                            curPage++;
                            if ((curPage >= 1) && (curPage <= Model.PageCount))
                            {
                                if (curPage == Model.PageIndex)
                                {
                                    <li class="active">
                                        <a href="javascript:void(0)">
                                            @Model.PageIndex<span class="sr-only"></span>
                                        </a>
                                    </li>
                                    break;
                                }
                                else
                                {
                                    <li>
                                        <a href='@PageHelper.GetPagerUrl(this.ViewContext, curPage)'>
                                            @curPage <span class="sr-only"> @curPage </span>
                                        </a>
                                    </li>
                                }
                            }
                        }
                    }
                }
                @if (Model.HasNextPage)
                {
                    <li>
                        <a href='@PageHelper.GetPagerUrl(this.ViewContext,Model.PageIndex + 1)' aria-label="Next">
                            <span aria-hidden="true">&raquo;</span>
                        </a>
                    </li>
                }
                else
                {
                    <li class="disabled">
                        <a href="javascript:void(0)" aria-label="Next">
                            <span aria-hidden="true">&raquo;</span>
                        </a>
                    </li>
                }
            </ul>
        </nav>
        <div>
            <span>每页有<strong>@Model.PageSize</strong>条数据，一共有<strong>@Model.PageCount</strong>页，总计<strong>@Model.TotalCount</strong>条数据</span>
        </div>
    </div>
    //}
}